<?php
namespace TwinPeaks\Core;
/**
 * This class is used for the safe termination of the method chaining 
 */
class CDummy
{
	/**
	 * @var integer
	 */
	private $hopsCounter;
	
	/**
	 * @var object
	 */
	private $originObj;
	
	/**
	 * @return
	 */
	function __construct()
	{
		$this->hopsCounter = -1;
	}

	/**
	 * @return CDummy
	 */
	function __call($name, $args)
	{
		if ($this->hopsCounter < 0)
			return $this;
		elseif ($this->hopsCounter == 0)
		{
			$this->hopsCounter = -1;
			return call_user_func_array([$this->originObj, $name], $args);
		}		
		$this->hopsCounter--;
		return $this;
	}
	
	/**
	 * @return ''
	 */
	function __toString()
	{
		return '';
	}
	
	/**
	 * @return void
	 */
	function setHopsCounter($num, $object)
	{
		$this->hopsCounter = $num;
		$this->originObj = $object;
	}
}
